#include "./app_task.h"
#include "../device/compat.h"
#include "../service/recv_service.h"
#include "../driver/cmd_uart.h"
#include "../driver/analog.h"
#include "../driver/door_motor.h"
#include "../driver/mux.h"
#include "../driver/sensor.h"
#include "./handler_task.h"
#include "../driver/nozzle_motor.h"
#include "./status_task.h"
#include "../driver/parts.h"
#include "./draw_task.h"
#include "./heat_task.h"
#include "../service/config.h"
#include "./rf_task.h"

namespace task {

using namespace driver;
using namespace service;

static void global_init() {

    RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
    AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
}

void AppTask::run() {

    global_init();
    cmdUart.init();
    analog.init();
    doorMotor.init();
    mux.init();
    sensor.init();
    nozzleMotor.init();
    parts.init();
    config.load();

    rfTask->start();
    heatTask->start();
    handlerTask->start();
    statusTask->start();
    drawTask->start();
    
    cmdUart->log("app run");

    recv_loop();
}

}
